<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>入库管理</title>
<meta name="decorator" content="default" />
<script type="text/javascript">
	function checkAndUpdateEmployees() {
		var id = document.getElementById("employeeProductID").value;
		if (id < 1) {
			alert("请先选择产品服务专员");
			return false;
		} else {
			document.getElementById("employeeProduct-ID").value = id;
		}
		return true;

	}

	function beforeSave(form) {
		var ps = "${inventoryIn.storeselfProducts[0]}";
		if (ps != "") {
			var content = "在保存入库单前，请再次确认本次入库产品，数量及进货价格是否全部正确？";
			global.confirm(content, function() {
				form.submit();
			});
		} else {
			global.confirm("请先登记全部入库产品", function() {
			});
			return false;
		}
		return false;

	};

	function doCancel() {
		var content = "返回后，本次入库数据将会丢失，确认取消入库？";
		global.confirm(content, function() {
			var url = "${ctx}/inventory/in/product/cancel";
			window.location.href = url;
		});
		return false;
	};

	$().ready(function() {
	});

	function page(n, s) {
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#pageForm").submit();
		return false;
	}
</script>

</head>
<body>
	<div class="container">
		<form:form id="inventoryInForm" modelAttribute="inventoryIn"
			action="${ctx}/inventory/in/storeselfProduct/save" method="post"
			class="form-input" onsubmit="return beforeSave(this)">
			<div class="icon-buttons">
				<input data-inline="true" type="button" data-icon="back"
					data-iconpos="notext" onclick="doCancel()" value="返回" /> <input
					data-inline="true" data-icon="check" data-iconpos="notext"
					type="submit" value="保存入库单" />
			</div>
			<div data-role="fieldcontain">
				<label for="employeeID">入库员工:</label>
				<form:select id="employeeID" data-native-menu="false"
					path="employee.id" name="employeeID">
					<c:forEach var="e" items="${employees}">
						<option value="${e.id}"
							${e.id==inventoryIn.employee.id?'selected':''}>${e.name}</option>
					</c:forEach>
				</form:select>
			</div>
			<div data-role="fieldcontain">
				<label for="dateTime">进货入库时间:</label>
				<form:input path="dateTime" readonly="true" />
			</div>
			<div data-role="fieldcontain">
				<label for="systemProduct">进货产品渠道:</label>
				<form:input path="systemProduct" readonly="true"
					value="${inventoryIn.systemProduct?'系统产品':'店面自营'}" />
			</div>
			<div data-role="fieldcontain">
				<label for="remark">备注说明:</label>
				<form:textarea path="remark" />
			</div>
			<a href="${ctx}/inventory/in/storeselfproduct/addpage"
				data-role="button" data-inline="true">添加产品</a>
		</form:form>
		<form:form id="pageForm" action="${ctx}/inventory/in/product/page"
			method="post" class="form-input">
			<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}" />
			<input id="pageSize" name="pageSize" type="hidden"
				value="${page.pageSize}" />
			<table id="contentTable" data-role="table"
				class="ui-responsive table-stroke">
				<thead>
					<tr>
						<th colspan="7" style="text-align:center;">已选产品</th>
					</tr>
					<tr>
						<th>入库产品</th>
						<th>产品规格</th>
						<th>入库数量</th>
						<th>零售价</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${page.list}" var="inProduct">
						<tr>
							<td>${inProduct.product.storeSelfProduct.name}</td>
							<td>${inProduct.product.storeSelfProduct.spec}</td>
							<td>${inProduct.amount}</td>
							<td>${inProduct.product.storeSelfProduct.retail_price}</td>
							<td><a data-role="button" data-inline="true"
								href="${ctx}/inventory/in/storeselfProduct/edit?id=${inProduct.product.id}&pageNo=${page.pageNo}&pageSize=${page.pageSize}">修改</a>&nbsp;&nbsp;
								<a data-role="button" data-inline="true"
								href="${ctx}/inventory/in/storeselfProduct/delete?id=${inProduct.product.id}&pageNo=${page.pageNo}&pageSize=${page.pageSize}">删除</a>&nbsp;&nbsp;
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
			<div class="pagination">${page}</div>

		</form:form>

		<div data-role="popup" id="inventoryInSelectionProduct">
			<form:form id="inventoryInForm"
				action="${ctx}/inventory/in/storeselfProduct/add" class="form-input"
				modelAttribute="inProduct">
				<div>
					<h3 id="myModalLabel">添加产品</h3>
				</div>
				<div>
					<form:hidden path="product.id" id="product-id" />
					<div class="control-group">
						<label>产品名称</label>
						<form:input type="text" id="product-name" readonly="true"
							path="product.storeSelfProduct.name" />
						<a href="#selectProduct" data-rel="popup"
							data-position-to="window" data-transition="pop"
							data-role="button" onclick="searchProduct()">添加产品</a>
					</div>
					<div class="control-group">
						<label>产品规格</label>
						<div class="controls">
							<form:input path="product.storeSelfProduct.spec" type="text"
								id="product-spec" readonly="true" />
						</div>
					</div>
					<div class="control-group">
						<label>零售价</label>
						<div class="controls">
							<form:input path="product.storeSelfProduct.retail_price"
								type="text" id="product-retail_price" readonly="true" />
						</div>
					</div>
					<div class="control-group">
						<label>进货数量</label>
						<div class="controls">
							<form:input path="amount" type="text" id="storeProduct-count" />
						</div>
					</div>
				</div>
				<div data-role="footer">
					<input class="btn " type="submit" value="保存" />&nbsp; <a href="#"
						data-rel="back" data-role="button" data-inline="true"
						data-icon="back">取消</a>
				</div>
			</form:form>
		</div>
	</div>
</body>
</html>
